package com.deyuanyun.pic.pipe.validatefun;

import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.util.ObjectUtil;
import com.deyuanyun.pic.common.validator.vinterface.ValidateInterface;
import com.deyuanyun.pic.settings.domain.pipe.PipeLine;
import com.deyuanyun.pic.settings.service.pipe.PipeLineService;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.Field;

public class PipeLineValidata implements ValidateInterface {

	@Override
	public <T, E,C> boolean apply(T t, E e,C c) {
		if(ObjectUtil.isNotNullEmpty(t)){

			PipeLineService service=SpringAppliction.getBean(PipeLineService.class);
			PipeLine pipeLine= service.getLineByName(((String)t).trim());//PipeDictUtils.getLineIdByName(((String) t).trim());
			if ("1".equals(pipeLine.getState())){
				return false;
			}
			Field f=(Field) e;
			try {
				BeanUtils.setProperty(c,f.getName(),pipeLine.getId());
			} catch (Exception e1) {
				e1.printStackTrace();
				return false;
			}
			return true;
		}
		return true;
	}

	@Override
	public String getName() {
		return null;
	}

}
